package com.shop.loan.proxy;

import com.shop.loan.mapper.ChannelByMybatisMapper;
import com.shop.loan.model.Product;
import org.springframework.stereotype.Service;
import xyz.erupt.annotation.fun.DataProxy;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;

@Service
public class ProductProxy implements DataProxy<Product> {

    @Resource
    ChannelByMybatisMapper channelByMybatisMapper;

    @Override
    public void afterFetch(Collection<Map<String, Object>> list) {
        if (list == null) {
            return;
        }
        for (Map<String, Object> stringObjectMap : list) {
            String idStr = stringObjectMap.get("id").toString();
            List<String> channelList = channelByMybatisMapper.selectListNameByProduct(Long.parseLong(idStr));
            stringObjectMap.put("channelNames", channelList.toString());
        }
    }
}
